
// Promise Demo ****
export function testFun (params) {
  return new Promise((resolve, reject) => {
    if (params > 0 && params < 10) {
      resolve('这大于了0，却是小了10岁')
    } else if (params > 10 && params < 15) {
      resolve('他们10岁以上，在15以内')
    } else {
      reject('年龄超标了')
    }
  })
}

// 解构赋值
// const arr = ['red', 'green', 'blue']
// const [fir, ...res] = arr
// console.log(fir, res)
// const numbers = [1, 2, 3, 4, 5]
// function printFirstTwo ([first, second]) {
//   console.log(`The first two elements are ${first} and ${second}.`)
// }

// printFirstTwo(numbers) // 输出 "The first two elements are 1 and 2."

// const obj = {
//   age: 18,
//   name: 'bbb',
//   gender: '女',
//   address: '成都'
// }
// const { age, names } = obj
// console.log(age, names)

// 书写防抖函数
export function debounce (fn, timer = 300) {
  let tag = null
  return function (...args) {
    if (tag != null) {
      clearTimeout(tag)
      tag = null
    }
    tag = setTimeout(() => {
      fn.call(this, ...args)
    }, timer)
  }
}

// 节流
// export function throttle (fn, timer) {
//   const tag = 0
//   return function (params) {
//     const now = +new Date()

//   }
// }
